home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 1999 #2 / Amiga Plus CD - 1999 - No. 2.iso / System-Boost / Workbench / ToolManager / Source / Prefs / misc.c < prev    next >
C/C++ Source or Header  |  1998-06-17  |  7KB  |  249 lines

  1. /*
  2.  * misc.c  V3.1
  3.  *
  4.  * Preferences editor miscellaneous routines
  5.  *
  6.  * Copyright (C) 1990-98 Stefan Becker
  7.  *
  8.  * This source code is for educational purposes only. You may study it
  9.  * and copy ideas or algorithms from it for your own projects. It is
  10.  * not allowed to use any of the source codes (in full or in parts)
  11.  * in other programs. Especially it is not allowed to create variants
  12.  * of ToolManager or ToolManager-like programs from this source code.
  13.  *
  14.  */
  15.  
  16. #include "toolmanager.h"
  17.  
  18. #ifdef _DCC
  19. /* VarArgs stub for NewObjectA */
  20. APTR NewObject(struct IClass *class, UBYTE *classID, Tag tag1, ... )
  21. {
  22.  return(NewObjectA(class, classID, (struct TagItem *) &tag1));
  23. }
  24.  
  25. /* VarArgs stub for SetAttrsA */
  26. ULONG SetAttrs(APTR obj, Tag tag1, ...)
  27. {
  28.  return(SetAttrsA(obj, (struct TagItem *) &tag1));
  29. }
  30.  
  31. /* VarArgs stub for MUI_NewObjectA */
  32. Object *MUI_NewObject(char *classname, Tag tag1, ...)
  33. {
  34.  return(MUI_NewObjectA(classname, (struct TagItem *) &tag1));
  35. }
  36.  
  37. /* VarArgs stub for MUI_MakeObjectA */
  38. Object *MUI_MakeObject(LONG type, ...)
  39. {
  40.  return(MUI_MakeObjectA(type, (ULONG *) &type + 1));
  41. }
  42.  
  43. /* VarArgs stub for MUI_RequestA */
  44. LONG MUI_Request(APTR app, APTR win, LONGBITS flags, char *title,
  45.                  char *gadgets, char *format, ...)
  46. {
  47.  return(MUI_RequestA(app, win, flags, title, gadgets, format,
  48.                      (APTR) (&format + 1)));
  49. }
  50.  
  51. /* VarArgs stub for MUI_AllocAslRequest */
  52. APTR MUI_AllocAslRequestTags(ULONG type, Tag tag1, ...)
  53. {
  54.  return(MUI_AllocAslRequest(type, (struct TagItem *) &tag1));
  55. }
  56.  
  57. /* VarArgs stub for MUI_AslRequestTags */
  58. BOOL MUI_AslRequestTags(APTR req, Tag tag1, ...)
  59. {
  60.  return(MUI_AslRequest(req, (struct TagItem *) &tag1));
  61. }
  62.  
  63. /* MUI class names */
  64. const char MUIC_Application[]   = "Application.mui";
  65. const char MUIC_Cycle[]         = "Cycle.mui";
  66. const char MUIC_Group[]         = "Group.mui";
  67. const char MUIC_List[]          = "List.mui";
  68. const char MUIC_Listtree[]      = "Listtree.mcc";
  69. const char MUIC_Listview[]      = "Listview.mui";
  70. const char MUIC_Menu[]          = "Menu.mui";
  71. const char MUIC_Menuitem[]      = "Menuitem.mui";
  72. const char MUIC_Menustrip[]     = "Menustrip.mui";
  73. const char MUIC_Numericbutton[] = "Numericbutton.mui";
  74. const char MUIC_Popasl[]        = "Popasl.mui";
  75. const char MUIC_Pophotkey[]     = "Pophotkey.mcc";
  76. const char MUIC_Poplist[]       = "Poplist.mui";
  77. const char MUIC_Popscreen[]     = "Popscreen.mui";
  78. const char MUIC_Popport[]       = "Popport.mcc";
  79. const char MUIC_Popposition[]   = "Popposition.mcc";
  80. const char MUIC_Register[]      = "Register.mui";
  81. const char MUIC_String[]        = "String.mui";
  82. const char MUIC_Text[]          = "Text.mui";
  83. const char MUIC_Window[]        = "Window.mui";
  84. #endif
  85.  
  86. /* Perform OM_NEW method on super class */
  87. ULONG DoSuperNew(Class *cl, Object *obj, Tag tag1, ...)
  88. {
  89.  return(DoSuperMethod(cl, obj, OM_NEW, &tag1, NULL));
  90. }
  91.  
  92. /* Duplicate a string */
  93. #undef  DEBUGFUNCTION
  94. #define DEBUGFUNCTION DuplicateString
  95. char *DuplicateString(const char *s)
  96. {
  97.  char *rc;
  98.  
  99.  /* Allocate memory for string and copy string */
  100.  if (rc = GetVector(strlen(s) + 1)) strcpy(rc, s);
  101.  
  102.  MISC_LOG(LOG1(Result, "0x%08lx", rc))
  103.  
  104.  /* Return pointer to new string */
  105.  return(rc);
  106. }
  107.  
  108. /* Duplicate a string from a MUI string object */
  109. #undef  DEBUGFUNCTION
  110. #define DEBUGFUNCTION GetStringContents
  111. char *GetStringContents(Object *obj, const char *s)
  112. {
  113.  char *rc;
  114.  
  115.  /* Get string contents */
  116.  GetAttr(MUIA_String_Contents, obj, (ULONG *) &rc);
  117.  
  118.  MISC_LOG(LOG2(Contents, "'%s' (0x%08lx)", rc, rc))
  119.  
  120.  /* Return NULL for empty string otherwise duplicate new contents*/
  121.  rc = (*rc == '\0') ? NULL : DuplicateString(rc);
  122.  
  123.  /* Old string valid? Free it */
  124.  if (s) FreeVector(s);
  125.  
  126.  MISC_LOG(LOG1(Result, "0x%08lx", rc))
  127.  
  128.  /* Return pointer to new/old string */
  129.  return(rc);
  130. }
  131.  
  132. /* Get state of checkmark gadget and return "value" if selected */
  133. #undef  DEBUGFUNCTION
  134. #define DEBUGFUNCTION GetCheckmarkState
  135. ULONG GetCheckmarkState(Object *obj, ULONG value)
  136. {
  137.  ULONG state;
  138.  
  139.  /* Get checkmark state */
  140.  GetAttr(MUIA_Selected, obj, &state);
  141.  
  142.  MISC_LOG(LOG1(State, "%ld", state))
  143.  
  144.  /* Return 0 or "value" depending on selected state */
  145.  return(state ? value : 0);
  146. }
  147.  
  148. /* Get state of checkit menu item and return "value" if selected */
  149. #undef  DEBUGFUNCTION
  150. #define DEBUGFUNCTION GetCheckitState
  151. ULONG GetCheckitState(Object *obj, ULONG value)
  152. {
  153.  ULONG state;
  154.  
  155.  /* Get checkmark state */
  156.  GetAttr(MUIA_Menuitem_Checked, obj, &state);
  157.  
  158.  MISC_LOG(LOG1(State, "%ld", state))
  159.  
  160.  /* Return 0 or "value" depending on selected state */
  161.  return(state ? value : 0);
  162. }
  163.  
  164. /* Get attach data from DropArea object */
  165. #undef  DEBUGFUNCTION
  166. #define DEBUGFUNCTION GetAttachData
  167. struct AttachData *GetAttachData(Object *drop, Object *obj,
  168.                                  struct AttachData *old)
  169. {
  170.  struct AttachData *rc  = NULL;
  171.  struct AttachData *new;
  172.  
  173.  /* Detach old object */
  174.  if (old) DoMethod(old->ad_Object, TMM_Detach, old);
  175.  
  176.  /* Ask DropArea object about attach data */
  177.  GetAttr(TMA_Attach, drop, (ULONG *) &new);
  178.  
  179.  MISC_LOG(LOG1(Attach, "0x%08lx", new))
  180.  
  181.  /* Data valid? Yes, attach to new object */
  182.  if (new) rc = (struct AttachData *) DoMethod(new->ad_Object, TMM_Attach, obj);
  183.  
  184.  MISC_LOG(LOG1(Result, "0x%08lx", rc))
  185.  
  186.  /* Return pointer to new attach data */
  187.  return(rc);
  188. }
  189.  
  190. /* Set disabled state of a gadget */
  191. #undef  DEBUGFUNCTION
  192. #define DEBUGFUNCTION SetDisabledState
  193. void SetDisabledState(Object *obj, ULONG state)
  194. {
  195.  MISC_LOG(LOG1(State, "%ld", state))
  196.  
  197.  SetAttrs(obj, MUIA_Disabled, state, TAG_DONE);
  198. }
  199.  
  200. /* Make a button and insert it into the TAB cycle chain */
  201. #undef  DEBUGFUNCTION
  202. #define DEBUGFUNCTION MakeButton
  203. Object *MakeButton(const char *label, const char *help)
  204. {
  205.  Object *rc;
  206.  
  207.  /* Create button */
  208.  if (rc = SimpleButton(label)) {
  209.  
  210.   MISC_LOG(LOG0(Button created))
  211.  
  212.   /* Insert into cycle chain and add bubble help */
  213.   SetAttrs(rc, MUIA_CycleChain, TRUE,
  214.                MUIA_ShortHelp,  help,
  215.                TAG_DONE);
  216.  }
  217.  
  218.  MISC_LOG(LOG1(Result, "0x%08lx", rc))
  219.  
  220.  return(rc);
  221. }
  222.  
  223. /* Make a checkmark and insert it into the TAB cycle chain */
  224. #undef  DEBUGFUNCTION
  225. #define DEBUGFUNCTION MakeCheckmark
  226. Object *MakeCheckmark(ULONG selected, const char *help)
  227. {
  228.  Object *rc;
  229.  
  230.  /* Create button */
  231.  if (rc = MUI_MakeObject(MUIO_Checkmark, NULL)) {
  232.  
  233.   MISC_LOG(LOG0(Button created))
  234.  
  235.   /* Set selected state,insert into cycle chain and add bubble help */
  236.   SetAttrs(rc, MUIA_Selected,   selected,
  237.                MUIA_CycleChain, TRUE,
  238.                MUIA_ShortHelp,  help,
  239.                TAG_DONE);
  240.  }
  241.  
  242.  MISC_LOG(LOG1(Result, "0x%08lx", rc))
  243.  
  244.  return(rc);
  245. }
  246.  
  247. /* Include global miscellaneous code */
  248. #include "/global_misc.c"
  249.